<template>
	<view class="view-root">
		<view class="tab-item" v-for="(item,index) in dataList" :key="item.id" @tap="onTabClick(index)">
			<view class="item-infos"
				:style="currentIndex == index ? ('background: linear-gradient(180deg, ' + (item.backColorTop) + ' 0%,' + (item.backColor) +  ' 100%)') : 'background: #EAEAEA' ">
				<image class="item-img" :src="currentIndex == index ? item.selectImg : item.unselectImg"></image>
				<view class="item-title">{{$t(item.name)}}</view>
			</view>
			
			<view class="item-sign" :style="currentIndex == index ? 'background:' + (item.activeColorBar) : 'background: #fff'"></view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'UniGrid',
		props: {
			dataList: {
				type: Array
			},
		},

		data() {
			return {
				currentIndex: 0
			}
		},
		
		methods:{
			onTabClick(e) {
				console.log(e)
				if(!this.dataList[e].name)
					return;
					
				this.currentIndex = e;
				this.$emit("onTabSelect", e);
			}
		}
	}
</script>

<style scoped lang="scss">
	.view-root {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.tab-item {
		display: flex;
		flex-direction: column;
		align-items: center;

		.item-infos {
			width: 128rpx;
			height: 128rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 19rpx 20rpx;
			border-radius: 10%;

			.item-img {
				width: 65rpx;
				height: 65rpx;
			}

			.item-title {
				font-size: 20rpx;
				font-family: SourceHanSansCN-Medium, SourceHanSansCN;
				font-weight: 700;
				color: #2A2A2A;
				margin-top: 10upx;
				min-height: 23upx;
			}
		}

		.item-sign {
			width: 100%;
			height: 6rpx;
			margin-top: 10rpx;
		}
	}
</style>
